<template>
  <div class="box">
   <!-- 头部搜索模块 -->
    <!-- <headerSearch :selectObj="selectObject" :isShowAdd="menuFlag" :isShowAud="menuAud" :goSearchFc="searchClick" :addFun="add" :auditFun="auitFun" /> -->
    <div class="search_form">
			<div>
				<el-select
					size="mini"
					clearable
					placeholder="客户类型"
					v-model="paramform.customerType"
					class="others"
					popper-class="selectClass"
				>
					<el-option v-for="(item, index) in cusType" :key="index" :label="item.dictLabel" :value="item.dictValue"></el-option>
				</el-select>
        <el-input size="mini" v-model="paramform.customerName" placeholder="客户名称" class="others" clearable></el-input>

				<el-button class="search_btn" type="primary" icon="el-icon-search" size="mini" @click="searchClick">查询</el-button>
			</div>
      <div>
        <el-button type="primary" size="mini" @click="add" icon="el-icon-plus" v-hasPermi="['metaDataManagement:Customer:customerInsert']">新建</el-button>
        <el-button type="primary" size="mini" @click="openCreaditLimit" v-hasPermi="['metaDataManagement:Customer:addCreditLimit']">信用额度</el-button>
        <!-- <el-button type="primary" size="mini" @click="auitFun" v-hasPermi="['metaDataManagement:Customer:customerAudit']">审核</el-button> -->
      </div>
    </div>
    <!-- 中间表格模块 -->
    <BaseTable
      :data="cargotableData"
      :columns="cargotableDataColumns"
      :tableHeight="tableHeight"
      :pagination="false"
      :loading="loading"
      @details="handlerClickDetail"
    >
      <el-table-column
          fixed="right"
          align="center"
          label="操作"
          slot="operationColumn"
          width="220px">
        <template slot-scope="scope">
          <el-button
              size="mini"
              title="编辑"
              v-hasPermi="['metaDataManagement:Customer:customerUpdate']"
              @click.stop="handleEdit(scope.$index, scope.row)"><span style="color:#0B6CD6"><i class='iconfont icon-1-07'></i>编辑</span></el-button>
          
            <el-button
              size="mini"
              title="删除"
              v-hasPermi="['metaDataManagement:Customer:customerDelete']"
              @click.stop="handlerDelete(scope.$index,scope.row)"><span style="color:#F75E5E"><i class='iconfont icon-1-08'></i>删除</span></el-button>
        </template>
      </el-table-column>
    </BaseTable>
    <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="startpage"
        :page-sizes="[10, 15, 20, 25, 30]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalNum"
      ></el-pagination>
    </div>
    <!-- 新增编辑客户信息 -->
    <div class="kehuguanxi">
      <el-drawer :before-close="handleClose" title="客户关系" :visible.sync="relation" direction="rtl">
        <div class="headerspan">
          <p v-cloak>{{ companyName }}</p>
        </div>
        <div class="headerspan-item">下属机构</div>
        <div class="form-t">
          <el-form>
            <el-form-item :label-width="formLabelWidth">
              <el-checkbox-group v-model="checkedComp" @change="compChange">
                <el-checkbox
                  v-for="(city, index) in comp"
                  :label="city.companyName"
                  :key="index"
                >{{ city.companyName }}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-form>
        </div>
        <div class="demo-drawer__footer">
          <el-button
            size="small"
            type="primary"
            @click="customerSyscomp()"
            :loading="loading"
          >{{ loading ? '提交中 ...' : '保 存' }}</el-button>
        </div>
      </el-drawer>
    </div>
    <div class="leftbox" v-if="drawer">
      <el-drawer
        :before-close="handleClose"
        :title="flag ? '新增客户信息' : '修改客户信息'"
        :visible.sync="drawer"
        direction="rtl"
        size="45%"
      >
        <el-form :model="form" :rules="basisRules" ref="basisRulesRef" style="padding:10px 20px;background-color:#fff">
          <el-form-item label="客户名称" prop="customerName" :label-width="formLabelWidth">
            <el-input
              @blur="inputFp(form.customerName)"
              v-model="form.customerName"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="客户简称" prop="customerShortName" :label-width="formLabelWidth">
            <el-input
              @input="form.customerShortName = verifyfilter('char', form.customerShortName)"
              v-model="form.customerShortName"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item prop="customerType" label="客户类型" :label-width="formLabelWidth">
            <el-radio-group v-model="form.customerType" size="mini">
              <el-radio :label="'1'">国内</el-radio>
              <el-radio :label="'2'">国外</el-radio>
              <el-radio :label="'3'">个人</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="客户属性" :label-width="formLabelWidth">
            <el-checkbox-group v-model="checkedCus" @change="cusChange">
              <el-checkbox
                  v-for="cus in cusTypeList"
                  :label="cus.dictLabel"
                  :key="cus.dictValue"
                >{{ cus.dictLabel }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="信用额度" prop="creditLimit" :label-width="formLabelWidth">
            <el-input
              @input="form.creditLimit = verifyfilter('latin', form.creditLimit)"
              v-model="form.creditLimit"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="抬头发票" prop="invoice" :label-width="formLabelWidth">
            <el-input
              @input="form.invoice = verifyfilter('char', form.invoice)"
              v-model="form.invoice"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="纳税人识别号" :label-width="formLabelWidth" prop="tin">
            <el-input
              v-model="form.tin"
              @input="form.tin = verifyfilter('duty', form.tin)"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="开户银行" prop="bank" :label-width="formLabelWidth">
            <el-input
              @input="form.bank = verifyfilter('char', form.bank)"
              v-model="form.bank"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="银行账号" prop="bankAccount" :label-width="formLabelWidth">
            <el-input
              @input="form.bankAccount = verifyfilter('number', form.bankAccount)"
              v-model="form.bankAccount"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="地址" prop="address" :label-width="formLabelWidth">
            <el-input
              v-model="form.address"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系人" prop="contact" :label-width="formLabelWidth">
            <el-input
              @input="form.contact = verifyfilter('char',form.contact)"
              v-model="form.contact"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="电话" prop="contactNumber" :label-width="formLabelWidth">
            <el-input
              @input="form.contactNumber = verifyfilter('phone', form.contactNumber)"
              v-model="form.contactNumber"
              maxlength="15"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业联系电话" prop="telephoneNumber" :label-width="formLabelWidth">
            <el-input
              @input="form.telephoneNumber = verifyfilter('phone', form.telephoneNumber)"
              v-model="form.telephoneNumber"
              maxlength="15"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业地址" prop="contactAddress" :label-width="formLabelWidth">
            <el-input
              v-model="form.contactAddress"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="联系人身份证" :label-width="formLabelWidth">
            <el-input
              @input="form.identityCard = verifyfilter('cardNum',form.identityCard)"
              v-model="form.identityCard"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="备注" :label-width="formLabelWidth">
            <el-input
              type="textarea"
              maxlength="500"
              show-word-limit
              v-model="form.remark"
              autocomplete="off"
              size="mini"
            ></el-input>
          </el-form-item>
          <el-form-item label="营业执照" :label-width="formLabelWidth">
            <Upload @changeFile="changeFile" :fileListEdit="businessLicenseList" :fileTypeA="'1'" />
          </el-form-item>
          <el-form-item label="授权书" :label-width="formLabelWidth">
            <Upload @changeFile="changeFile" :fileListEdit="authorizationList" :fileTypeA="'2'"/>
          </el-form-item>
          <el-form-item label="企业开票信息" :label-width="formLabelWidth">
            <Upload @changeFile="changeFile" :fileListEdit="drawerBillFile" :fileTypeA="'3'"/>
          </el-form-item>
        </el-form>

        <div class="demo-drawer__footer">
          <el-button
            size="small"
            type="primary"
            @click="addUpdate()"
            :loading="isSaveLoading"
          >{{ isSaveLoading ? '提交中 ...' : '保 存' }}</el-button>
        </div>
      </el-drawer>
    </div>
    <!-- 新增开票附加信息 -->
    <div class="leftbox" v-if="recieptDrawer">
      <el-drawer
        :before-close="handleClose1"
        :with-header="false"
        :visible.sync="recieptDrawer"
        direction="rtl"
        size="45%"
      >
      <div style="line-height: 45px;padding-left: 10px;padding-right: 10px;">
        <div style="float: left;">附加开票信息列表</div>
        <div class="collapseItemOption" style="float: right;">
            <el-tooltip class="item" content="新增" placement="top">
              <el-button size="mini" @click="showFun('add')">
                <i class="iconfont icon-tianjia"></i>
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" content="修改" placement="top">
              <el-button size="mini" @click="showFun('edit')" >
                <i class="iconfont icon-bianji"></i>
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" content="删除" placement="top">
              <el-button size="mini" @click="delCarriage">
                <i class="iconfont icon-shanchu"></i>
              </el-button>
            </el-tooltip>
          </div>
      </div>
      <!-- 附加开票信息列表 -->
        <BaseTable
          :data="recieptData"
          :columns="recieptaDataColumns"
          :tableHeight="recieptHeihgt"
          :pagination="false"
          :loading="loading"
          @details="getRow"
        ></BaseTable>

        <!-- <div class="demo-drawer__footer">
          <el-button
            size="small"
            type="primary"
            @click="addUpdate()"
            :loading="isSaveLoading"
          >{{ isSaveLoading ? '提交中 ...' : '保 存' }}</el-button>
        </div> -->
      </el-drawer>
    </div>
    <!-- 附加开票信息新增编辑 -->
    <el-drawer
      :before-close="handleClose1"
      :title="flagOut=='add' ? '新增附加开票信息' : '修改附加开票信息'"
      :visible.sync="isShowAdd"
      direction="rtl"
      size="32%"
    >
      <el-form
        :model="outForm"
        :rules="recieptRules"
        ref="outRefs"
        label-width="120px"
        style="padding:20px"
      >
        <el-form-item label="详细地址：" prop="address">
          <el-input v-model="outForm.address"></el-input>
        </el-form-item>
        <el-form-item label="联系电话：" prop="contactPhone">
          <el-input 
          v-model="outForm.contactPhone"
          @input="outForm.contactPhone=verifyfilter('phone',outForm.contactPhone)"
          ></el-input>
        </el-form-item>
        <el-form-item label="开户银行名称：" prop="bank">
          <el-input v-model="outForm.bank"></el-input>
        </el-form-item>
        <el-form-item label="开户银行账号：" prop="bankNum">
          <el-input 
          v-model="outForm.bankNum"
          @input="outForm.bankNum=verifyfilter('number',outForm.bankNum)"></el-input>
        </el-form-item>
      </el-form>
      <div class="demo-drawer__footer">
        <el-button type="primary" @click="submitReciept()" size="mini" :loading="outLoading">{{ outLoading ? '提交中 ...' : '保 存' }}</el-button>
      </div>
    </el-drawer>
    <el-dialog
      title="预览"
      :visible.sync="dialogVisible"
      :before-close="handleClose">
      <div>
        <img :src="imgurl" style="width:100%;height:auto"/>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="downLoadFile(fileInfo)">下载</el-button>
      </span>
    </el-dialog>
    <!-- 信用额度 -->
    <el-dialog
      title="编辑信用额度"
      width="25%"
      :visible.sync="creditDialog">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="信用额度:">
          <el-input v-model="formInline.creditLimit" size="mini" placeholder="信用额度"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="creditDialog = false">取 消</el-button>
        <el-button type="primary" @click="submitCreadit">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { isObjectValueEqual } from '@/libs/date'
import BaseTable from '@/components/BaseTable'
import headerSearch from './component/headerSearch'
import publicapi from '@/api/public/index'
import axios from 'axios'
import config from '@/network/config.js'
import api from '@/api/Basic/customer/index'
import Upload from '@/components/upload'
export default {
  name: 'metadataCustomer',
  components: {
    BaseTable,
    headerSearch,
    Upload
  },
  props: {
  },
  data() {
    return {
      paramform: {
        customerName: '',
        customerType: ''
      },
      imgurl: '',
      dialogVisible: false,
      recieptHeihgt: window.innerHeight - 100,
      outLoading: false, // 开票信息
      customerId: '', // 客户信息的id
      rowData: null, // 选择的数据
      isShowAdd: false, // 是否显示新增或编辑的页面
      flagOut: 'add', // 新增，编辑标识
      outForm: {
        address: '',
        contactPhone: '',
        bank: '',
        bankNum: '',
        customId: ''
      },
      recieptRules: {
        address: [
          {
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }
        ],
        contactPhone: [
          {
            required: true,
            message: '请输入联系电话',
            trigger: 'blur'
          }
        ],
        bank: [
          {
            required: true,
            message: '请输入开户银行名称',
            trigger: 'blur'
          }
        ],
        bankNum: [
          {
            required: true,
            message: '请选择开户银行账号',
            trigger: 'blur'
          }
        ]
      },
      isSaveLoading: false,
      cusType: [
        {
          dictValue: '1',
          dictLabel: '国内企业'
        }, {
          dictValue: '2',
          dictLabel: '国外企业'
        }, {
          dictValue: '3',
          dictLabel: '个人'
        }
      ],
      // 搜索框显示对象
      selectObject: [
        {
          name: '客户名称',
          type: 'inputVerify',
          verifyTpye: 'char',
          modelName: 'customerName'
        },
        {
          name: '客户类型',
          type: 'select',
          modelName: 'customerType',
          selectData: this.cusType
        }
      ],
      // 附加开票信息列
      recieptaDataColumns: [
        {
          prop: 'address',
          label: '详细地址'
        },
        {
          prop: 'bank',
          label: '开户银行名称'
        },
        {
          prop: 'bankNum',
          label: '开户银行账号'
        },
        {
          prop: 'contactPhone',
          label: '联系电话'
        }
      ],
      cargotableDataColumns: [
        {
          prop: 'customerCode',
          label: '客户代码'
        },
        {
          prop: 'customerName',
          label: '客户名称',
          width: 200
        },
        {
          prop: 'customerShortName',
          label: '客户简称'
        },
        {
          prop: 'customerType',
          label: '客户类型',
          render(h, params) {
            return h('span', {
              props: {
                size: 'mini'
              },
              domProps: {
                innerHTML: params.row.customerType == '1' ? '国内企业' : params.row.customerType == '2' ? '国外企业' : '个人'
              }
            })
          }
        },
        {
          prop: 'tin',
          label: '纳税人识别号'
        },
        {
          prop: 'invoice',
          label: '抬头发票'
        },
        {
          prop: 'address',
          label: '地址'
        },
        {
          prop: 'contactNumber',
          label: '电话'
        },
        {
          prop: 'status',
          label: '审核状态',
          render(h, params) {
            if (params.row.status == '1') {
              return h('el-tag', {
                props: {
                  size: 'mini'
                },
                domProps: {
                  innerHTML: '未审核'
                }
              })
            }
            if (params.row.status == '2') {
              return h('el-tag', {
                props: {
                  size: 'mini',
                  type: 'success'
                },
                domProps: {
                  innerHTML: '已审核'
                }
              })
            }
          }
        }
        // {
        //   label: '操作',
        //   fixed: 'right',
        //   align: 'center',
        //   width: '180',
        //   render: (h, params) => {
        //     return h(
        //       'div',
        //       {
        //         class: 'btnClass'
        //       },
        //       [
        //         h('el-button', {
        //           props: {
        //             size: 'mini'
        //           },

        //           domProps: {
        //             // 添加标签,使用自己引入的iconfont图标
        //             innerHTML:
        //               "<span style='color:#0B6CD6'><i class='iconfont icon-1-07'></i><span  style='padding-left:5px;'>编辑</span></span>"
        //           },
        //           on: {
        //             click: () => {
        //               this.handleEdit(params.$index, params.row)
        //             }
        //           }
        //         }),
        //         // h('el-button', {
        //         //   props: {
        //         //     size: 'mini'
        //         //   },
        //         //   style: {
        //         //     marginRight: '10px'
        //         //   },
        //         //   domProps: {
        //         //     // 添加标签,使用自己引入的iconfont图标
        //         //     innerHTML:
        //         //       `<span style='color:#9420A8;'><i class='iconfont icon-1-09'></i><span  style='padding-left:5px;'>附加开票</span></span>`

        //         //   },
        //         //   on: {
        //         //     click: () => {
        //         //       click: this.showRecieptList(params.$index, params.row)
        //         //     }
        //         //   }
        //         // }),
        //         h('el-button', {
        //           props: {
        //             size: 'mini'
        //           },
        //           style: {
        //             marginRight: '10px'
        //           },
        //           domProps: {
        //             // 添加标签,使用自己引入的iconfont图标
        //             innerHTML:
        //               `<span style='color:#f75e5e;'><i class='iconfont icon-1-08'></i><span  style='padding-left:5px;'>删除</span></span>`

        //           },
        //           on: {
        //             click: () => {
        //               this.handlerDelete(params.$index, params.row)
        //             }
        //           }
        //         })
        //       ]
        //     )
        //   }
        // }
      ],
      cargotableData: [],
      recieptData: [], // 附加开票信息列表
      // 基础信息验证
      basisRules: {
        customerType: [
          {
            required: true,
            message: '请选择客户类型',
            trigger: 'blur'
          }
        ],
        tin: [
          {
            required: true,
            message: '请输入纳税人识别号',
            trigger: 'blur'
          }
        ],
        invoice: [
          {
            required: true,
            message: '请输入发票抬头',
            trigger: 'blur'
          }
        ],
        contactNumber: [
          {
            required: true,
            message: '请输入手机号',
            trigger: 'blur'
          }
        ],
        telephoneNumber: [
          {
            required: true,
            message: '请输入企业联系电话',
            trigger: 'blur'
          }
        ],
        contactAddress: [
          {
            required: true,
            message: '请输入企业地址',
            trigger: 'blur'
          }
        ],
        bank: [
          {
            required: true,
            message: '请输入开户行',
            trigger: 'blur'
          }
        ],
        bankAccount: [
          {
            required: true,
            message: '请输入银行账号',
            trigger: 'blur'
          }
        ],
        address: [
          {
            required: true,
            message: '请输入地址',
            trigger: 'blur'
          }
        ],
        contact: [
          {
            required: true,
            message: '请输入联系人',
            trigger: 'blur'
          }
        ],
        customerName: [
          {
            required: true,
            message: '请输入客户名称',
            trigger: 'blur'
          },
          {
            min: 1,
            max: 50,
            message: '长度在 1 到 50 个字符',
            trigger: 'blur'
          }
        ],
        customerShortName: [
          {
            required: true,
            message: '请输入客户简称',
            trigger: 'blur'
          },
          {
            min: 1,
            max: 10,
            message: '长度在 1 到 10 个字符',
            trigger: 'blur'
          }
        ]

      },
      queryInfo: {
        fullName: '',
        companyTypeCode: ''
      }, // 查询参数
      flag: false,
      provinceData: [], // 所属省份
      cityData: [], // 所属城市
      ids: [], // 批量删除
      checkedCus: [], // 选中的客户
      customerType: [], // 客户类型复选框
      checkedComp: [],
      parentComp: [], // 母公司
      comp: [],
      popVal: '',
      form: {
        customerCode: '',
        customerName: '',
        customerShortName: '',
        customerType: '1',
        customerProperty: '',
        creditLimit: '',
        invoice: '',
        tin: '',
        bank: '',
        bankAccount: '',
        address: '',
        contact: '',
        contactNumber: '',
    		email: '',
    		identityCard: '',
    		remark: '',
        contactAddress: '',
        telephoneNumber: ''
      },
      formLabelWidth: '130px', // form的item宽度
      drawer: false, // 新增修改
      recieptDrawer: false, // 附加开票信息列表
      relation: false, // 关联
      loading: false,
      companyName: '', // 下属公司header
      tableData: [],

      nowData: {},
      // 分页
      startpage: 1,
      totalNum: 1,
      pagesize: 15,
      currentPage: 1, // 当前页
      selectId: [],
      arr: [],
      cusTypeCode: null,
      flagHint: false, // 抽屉是否提示,
      activeName: 'first', // tabs 默认显示
      firstName: '',
      checkId: '',
      oldName: '',
      menuArr: [],
      menuFlag: false,
      menuAud: false,
      cusTypeList: [],
      businessLicenseList: [], // 营业执照文件
      authorizationList: [], // 授权书文件
      mattachmentInfoList: [], // 文件集合
      fileInfo: null,
      drawerBillFile: [], // 企业开票信息
      formInline: {
        creditLimit: '' // 信用额度
      },
      creditDialog: false
    }
  },
  async activated() {
    var menuArr = []
    var menuId = ''
    if (localStorage.getItem('menuArr')) {
      menuArr = JSON.parse(localStorage.getItem('menuArr'))
    }
    menuArr.map(item => {
      item.children.map(v => {
        if (window.location.href.includes(v.url)) {
          menuId = v.id
          console.log(window.location.href)
          console.log(v.url)
          console.log(v.id)
        }
      })
    })

    if (menuId) {
      this.menuArr = []
      await publicapi.getPermissionsBtn(menuId)
        .then(res => {
          res.data.data.map(item => {
            this.menuArr.push(item.RESOURCENAME)
          })

          if (!this.menuArr.includes('客户资料按钮修改')) {
            this.cargotableDataColumns.map((item, index) => {
              if (item.label == '操作') {
                this.cargotableDataColumns.pop()
              }
            })
          }
          console.log(this.menuArr)
          if (!this.menuArr.includes('客户资料按钮新增')) {
            this.menuFlag = false
          } else {
            this.menuFlag = true
          }
          if (!this.menuArr.includes('客户资料按钮审核')) {
            this.menuAud = false
          } else {
            this.menuAud = true
          }
        }).catch((error) => {
        })
    }
    if (this.$store.state.app.searchResouce == 'menu') {
      this.queryInfo = {
        customerName: '',
        customerType: ''
      }
      // this.getListData()
      this.getCusType()
      this.getDict()
    }
  },
  watch: {
    form: {
      handler(newVal, oldVal) {
        // console.log(isObjectValueEqual(newVal, oldVal))
        this.flagHint = isObjectValueEqual(newVal, oldVal)
      },
      deep: true
    }
  },
  computed: {
    tableHeight: function() {
      return this.$store.state.tableHeight
    }
  },
  methods: {
    // 审核
    auitFun() {
      if (this.tableInfo == null) {
        return this.$message.error('请选择一条数据后再审核')
      }
      this.$confirm('将审核本条客户信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.auditdata(this.tableInfo.id).then(res => {
          this.$message({
            type: 'success',
            message: '审核成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消审核'
        });
      });
    },
    // 获取字典数据
    getDict() {
      publicapi.getDictData('CUSTOMER_PROPERTY').then(res => {
        this.cusTypeList = res.data.data.CUSTOMER_PROPERTY
        console.log(this.cusTypeList)
      })
    },
    submitReciept() {
      this.outLoading = true;
      this.outForm.customId = this.customerId;
      if (this.flagOut == 'add') {
        this.$http
          .post(
            `/wfpms-master-service/api/external/mtc_company_recieptadd/add`,
            this.outForm
          )
          .then((res) => {
            this.outLoading = false;
            // if (res.data.msg == "SUCCESS") {
            this.isShowAdd = false;
            this.getRecieptListData()
            // this.rowData = null;
            this.$notify.success({
              title: '温馨提示',
              message: '新增成功！'
            });
            this.rowData = null
            this.outForm = null
            // }
          })
          .catch(res => {
            this.outLoading = false
          })
      } else {
        this.$http
          .put(
            `/wfpms-master-service/api/external/mtc_company_recieptadd/updatebyid`,
            this.outForm
          )
          .then((res) => {
            this.outLoading = false;
            // if (res.data.msg == "SUCCESS") {
            this.isShowAdd = false;
            this.getRecieptListData()
            this.rowData = null;
            this.$notify.success({
              title: '温馨提示',
              message: '更新成功！'
            });
            this.outForm = null
            // }
          })
          .catch(res => {
            this.outLoading = false
          })
      }
    },
    // 选中附加开票表格行
    getRow(row) {
      this.rowData = JSON.parse(JSON.stringify(row));
      this.outForm = JSON.parse(JSON.stringify(row));
      console.log(this.rowData);
    },
    // 选中主列表行数据
    handlerClickDetail(row) {
      console.log(row)
      this.tableInfo = row
    },
    // 删除开票信息
    async delCarriage() {
      if (this.rowData) {
        console.log(this.rowData)
        const confirmRes = await this.$confirm(
          '此操作将永久删除该数据, 是否继续?',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).catch(err => {})
        if (confirmRes !== 'confirm') {
          return this.$message.info('已经取消删除')
        }
        // var listId = [];
        // this.selectList.map(item =>{
        //   listId.push(item.id)
        // })
        this.deleteRecieptById(this.rowData.id)
        this.rowData = null
        this.outForm = null
      } else {
        this.$message.warning('请选择需要删除的数据')
      }
    },
    // 删除选择的开票信信息
    async deleteRecieptById(id) {
      const res = await this.$http.delete(
        `/wfpms-master-service/api/external/mtc_company_recieptadd/deletebyid?id=${id}`
      )
      this.$notify.success({
        title: '温馨提示',
        message: '删除成功！'
      });
      this.getRecieptListData()
    },
    // 模态框关闭
    handleClose1(done) {
      // if (!Utils.compareData(this.oldVal, this.comfirmForm)) {
      // this.$confirm("修改的数据未保存，是否关闭？")
      //   .then((_) => {
      //     done();
      //   })
      //   .catch((_) => {});
      // } else {
      done();
      this.rowData = null
      this.outForm = {}
      // }
    },
    // 新增确报
    showFun(type) {
      console.log('新增编辑和rowdata', this.rowData)
      if (type == 'add') {
        this.outForm = {}
      } else {
        this.outForm = JSON.parse(JSON.stringify(this.rowData))
      }
      if (this.rowData || type == 'add') {
        console.log(this.rowData)
        this.flagOut = type;
        // 根据类型获取进行不同的操作
        // if(this.rowData)
        // {
        //   this.getCargosList({code:this.rowData.cargoinfoCode})
        //   this.comfirmForm = this.rowData;
        // }
        this.isShowAdd = true;
        // this.isAddConfirm = false;
        // this.comfirmForm = JSON.parse(JSON.stringify(this.rowData));
      } else {
        this.$message.warning('请选择需要修改的数据')
      }
    },
    checkTaxNum(rule, value, callback) {
      if (!value) return callback()
      var obj = {
        taxNum: value
      }
      if (this.checkId) {
        obj.id = this.checkId
      }
      this.$http.get('/wfpms-master-service/api/external/mtc_company/checktaxnum', { params: obj }).then(res => {
        console.log(res);
        if (res.data.data) {
          callback(new Error('税号已存在，请重新编辑税号信息'));
        } else {
          callback()
        }
      })
    },
    // tabs页
    handleTabsClick(tab, event) {
      // console.log(tab, event)
    },
    // 根据客户名称生成抬头发票
    inputFp(customername) {
      this.form.invoice = customername
    },

    // 所属城市
    async getcityData(z) {
      if (z) {
        // const that = this
        await this.$http.get(`/wfpms-master-service/api/external/public/getcitybyprovince?dm=${z}`
        ).then(res => {
          if (res.status == 200) {
            if (res.data.success) {
              this.cityData = res.data.data
              // console.log(this.cityData)
              let flag = false
              for (let i = 0; i < this.cityData.length; i++) {
                if (this.cityData[i].dm == this.form.city) {
                  flag = true
                  break
                }
              }
            }
          }
        }).catch(error => {})
      }
    },
    // 所属省份
    async getprovinceData() {
      const that = this
      const res = await this.$http.get(
        `/wfpms-master-service/api/external/public/getprovince`
      )
      if (res.status == 200) {
        if (res.data.success) {
          this.provinceData = res.data.data
        }
      }
      this.getcityData(this.form.province)
    },

    // wfpms-master-service/api/external/mtc_company/queryparent
    async queryparent(id) {
      if (id == undefined) {
        id = ''
      }
      const res = await this.$http.get(
        `/wfpms-master-service/api/external/mtc_company/queryparent?id=${id}`
      )
      // console.log(res)
      if (res.status == 200) {
        if (res.data.success) {
          this.parentComp = res.data.data.map(n => {
            return {
              fullName: n.fullName,
              id: n.id
            }
          })
        } else {
          // return this.$message.warning(res.data.msg)
        }
      } else {
        this.$message.error('获取数据失败！')
      }
    },
    async isSomecustomername(customername) {
      // 用户名唯一验证
      // if (this.firstName != customername||this.flag) {
      //   await this.$http.get(
      //     `/wfpms-master-service/api/external/mtc_company/checkcustomerbyname?customername=${customername}`
      //   ).then(res =>{
      //
      //
      //   if (res.data.data) {
      //     this.form.fullName = ''
      //      this.popVal = ""
      //     return this.$message.error('已存在此客户名称请重新输入')
      //   }
      //
      //   }).catch(error => {})
      //   // console.log('butong ')
      // } else {
      //   // console.log('名字相同')
      // }

      // 速记码
      const refer = await this.$http.get(
        `/wfpms-master-service/api/external/public/autorefer?name=${customername}`
      )
      this.form.shortCode = refer.data.data
    },
    // /wfpms-master-service/api/external/mtc_company/finddict
    async getSelectCusAdd() {
      const that = this
      const data = []
      const ids = []
      await this.$http.get(
        `/wfpms-master-service/api/external/mtc_company/finddict`
      ).then(res => {
        if (res.status == 200) {
          if (res.data.success) {
            this.customerType = res.data.data
            if (that.customerType.length !== 0) {
              for (const n of that.customerType) {
              // 如果绑定
                if (n.bind) {
                  data.push(n.dictLabel)
                  if (n.dictValue) {
                    ids.push(n.dictValue)
                  }
                }
              }
              this.checkedCus = data
              if (ids) {
                this.cusTypeCode = ids.join(',')
              }
            }
          }
        }
      }).catch(error => {})
    },
    // 获取客户类型
    async getSelectCus() {
      const that = this
      const data = []
      const ids = []
      const res = await this.$http.get(
        `/wfpms-master-service/api/external/mtc_company/finddictbyid?id=${this.form.id}`
      )
      // console.log(res)
      if (res.status == 200) {
        if (res.data.success) {
          this.customerType = res.data.data
          if (that.customerType.length !== 0) {
            for (const n of that.customerType) {
              // 如果绑定
              if (n.bind) {
                data.push(n.dictLabel)
                if (n.dictValue) {
                  ids.push(n.dictValue)
                }
              }
            }
            this.checkedCus = data
            if (ids) {
              this.cusTypeCode = ids.join(',')
            }

            // /////////2020/5/23 by liangd  初始化和change修改成一样的逻辑

            this.arr = this.customerType.filter(n =>
              this.checkedCus.includes(n.dictLabel)
            )
            this.arr.forEach(i => {
              i.bind = true
            })
            // trueId = that.comp.filter(n => n.bind).map(n => n.id);
          }
        }
      }
    },
    // 客户类型事件
    cusChange(v) {
      if (v.length !== 0) {
        this.checkedCus = v
        this.arr = this.cusTypeList.filter(n =>
          this.checkedCus.includes(n.dictLabel)
        )
        console.log(v)
        // this.flagHint = true
      }
    },
    // 获取客户类型
    async getCusType() {
      // const res = await this.$http.get(
      //   `/wfpms-master-service/api/external/public/listdict?dicttype=c_company_type`
      // )
      // this.cusType = res.data.data

      this.selectObject[1].selectData = this.cusType;
      // console.log(res.data.data)
    },

    handleClose(done) {
      if (this.flagHint) {
        this.$confirm('您已修改了数据，确定是否关闭？')
          .then(_ => {
            this.popVal = ''
            done()
          })
          .catch(_ => {})
      } else {
        this.popVal = ''
        done()
      }
    },

    // 选择
    handleSelectionChange(val) {
      this.ids = []
      var that = this
      val.map(n => {
        if (n.id) {
          that.ids.push(n.id)
        }
      })
      this.ids = this.newArr(that.ids)
    },

    // 下属机构改变
    compChange(v) {
      if (v.length !== 0) {
        this.checkedComp = v
        this.arr = this.comp.filter(n =>
          this.checkedComp.includes(n.companyName)
        )
        this.arr.forEach(i => {
          i.bind = true
        })
        if (this.checkedComp.length === 0) {
          this.arr = []
        }
      }
    },
    // 关联信息弹出请求
    async RelationFun(index, row) {
      this.nowData = row
      if (!this.relation) {
        this.relation = true
      }
      const that = this
      const data = []
      const ids = []
      await this.$http.get(
        `/wfpms-master-service/api/external/customerSyscomp/listcustomerbind?id=${row.id}`
      ).then(res => {
        if (res.data.success) {
          this.comp = res.data.data.bindList
          this.companyName = res.data.data.companyName
          if (that.comp.length !== 0) {
            for (const n of that.comp) {
            // 如果绑定
              if (n.bind) {
                data.push(n.companyName)
                if (n.id) {
                  ids.push(n.id)
                }
              }
            }
            this.checkedComp = this.newArr(data)
            this.selectId = this.newArr(ids)
          }
        } else {
          return that.$message.warning(res.data.msg)
        }
      }).catch(error => {})
    },
    newArr(arr) {
      return Array.from(new Set(arr))
    },
    // 客户关系
    async customerSyscomp() {
      const that = this
      let trueId = new Set()
      // this.comp = this.arr;
      if (that.checkedComp.length !== 0) {
        trueId = that.arr.filter(n => n.bind).map(n => n.id)
        if (trueId.length !== 0) {
          that.selectId = trueId
        }
        if (that.selectId.length !== 0) {
          const data = {
            compId: that.selectId.join(), // ['2','4','8'],
            customCompId: that.nowData.id
          }
          await that.$http.post(
            '/wfpms-master-service/api/external/mtc_company/issue',
            data
          ).then(res => {
            if (res.data.success) {
              if (that.relation) {
                that.relation = false
              }
              that.$message.success(res.data.msg)
              that.getListData()
            } else {
              return that.$message.warning(res.data.msg)
            }
          }).catch(error => {})
        }
      } else {
        that.selectId = []
        const data = {
          compId: that.selectId.join(), // ['2','4','8'],
          customCompId: that.nowData.id
          // compType: that.nowData.companyTypeCode
        }
        await that.$http.post(
          '/wfpms-master-service/api/external/mtc_company/issue',
          data
        ).then(res => {
          if (res.data.success) {
            if (that.relation) {
              that.relation = false
            }
            that.$message.success(res.data.msg)
            that.getListData()
          } else {
            return that.$message.warning(res.data.msg)
          }
        }).catch(error => {})
      }
    },
    // 查询调用
    searchClick() {
      this.startpage = 1
      this.queryInfo = Object.assign(this.paramform);
      this.getListData()
    },
    // 查询数据table数据
    async getListData() {
      this.loading = true
      await this.$http.get(
        `/wfpms-master-service/api/external/mtc_company/queryall?pagesize=${this.pagesize}&startpage=${this.startpage}`,
        {
          params: this.queryInfo
        }
      ).then(res => {
        this.cargotableData = res.data.data.pages
        // 分页
        this.startpage = res.data.data.pageNum // 当前页
        this.pagesize = res.data.data.pageSize // 每页多少
        this.totalNum = res.data.data.totalNum
        this.tableInfo = null
        this.loading = false
      }).catch(error => { this.loading = false })
    },
    // 查询附加开票信息
    async getRecieptListData() {
      this.loading = true
      await this.$http.get(
        `/wfpms-master-service/api/external/mtc_company_recieptadd/queryall?customcompanyid=${this.customerId}`
      ).then(res => {
        this.recieptData = res.data.data
        this.loading = false
        console.log('附加开票信息列表', this.recieptData)
      }).catch(error => { this.loading = false })
    },
    addUpdate() {
      if (this.checkedCus.length == 0) {
        return this.$message.warning('请勾选客户属性')
      }
      if (this.form.customerName) {
        let url = `/wfpms-master-service/api/external/mtc_company/${this.$version}/checkcustomer?fullName=${this.form.customerName}&id=`
        if (!this.flag) {
          url = `/wfpms-master-service/api/external/mtc_company/${this.$version}/checkcustomer?fullName=${this.form.customerName}&id=${this.form.id}`
        }
        this.$http.get(url).then(res => {
          if (res.data.data) {
            var flag = []
            var arr = []
            res.data.data.map(item => {
              arr.push(item.fullName)
            })
            flag = res.data.data
            this.popVal = arr
          } else {
            this.popVal = ''
          }
          if (this.popVal) {
            if (flag[0].flag) {
              this.$message.error('存在重复客户名称！')
              return
            }
            this.$confirm(`存在类似客户名:${this.popVal},是否继续保存?`, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.addUpdateNew()
              this.popVal = ''
            }).catch(() => {
            });
          } else {
            this.addUpdateNew()
            this.popVal = ''
          }
        })
      } else {
        this.addUpdateNew()
        this.popVal = ''
      }
    },
    addUpdateNew() {
      // 传递的参数等待确认
      delete this.form.createBy
      delete this.form.createName
      delete this.form.createTime
      delete this.form.updateBy
      delete this.form.updateName
      delete this.form.updateTime
      delete this.form.delFlag
      const that = this

      // 文件
      that.form.mattachmentInfoList = []
      if (this.businessLicenseList && this.businessLicenseList.length > 0) {
        this.businessLicenseList.forEach(v => {
          that.form.mattachmentInfoList.push(v)
        })
      }
      if (this.authorizationList && this.authorizationList.length > 0) {
        this.authorizationList.forEach(v => {
          that.form.mattachmentInfoList.push(v)
        })
      }
      if (this.drawerBillFile && this.drawerBillFile.length > 0) {
        this.drawerBillFile.forEach(v => {
          that.form.mattachmentInfoList.push(v)
        })
      }
      // flag为真进行添加操作
      that.$refs['basisRulesRef'].validate(valid => {
        if (valid) {
          this.isSaveLoading = true
          this.$confirm(`请确认发票抬头是否是：${this.form.invoice}?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            closeOnClickModal: false
          })
            .then(async(action, instance) => {
              if (that.flag) {
                delete this.form.id
                let trueId = new Set()
                trueId = this.arr.map(v => v.dictValue)
                console.log(trueId)
                this.cusTypeCode = trueId.join(',')
                if (this.cusTypeCode.length !== 0) {
                  that.form.customerProperty = this.cusTypeCode
                }
                await api.addcus(
                  that.form
                ).then(res => {
                  that.isSaveLoading = false
                  if (res.data.success) {
                    if (that.drawer) {
                      that.drawer = false
                    }
                    that.$message.success(res.data.msg)
                    that.getListData()
                  } else {
                    return that.$message.warning(res.data.msg)
                  }
                }
                ).catch(error => {
                  that.isSaveLoading = false;
                  // return that.$message.warning(error.data.msg)
                }
                )
              } else {
                // 进行修改操作elseRules
                let trueId = new Set()
                // this.customerType = this.arr;

                trueId = this.arr.map(v => v.dictValue)
                this.cusTypeCode = trueId.join(',')
                console.log(trueId)
                if (this.cusTypeCode.length !== 0) {
                  that.form.customerProperty = this.cusTypeCode
                } else {
                  that.isSaveLoading = false;
                  return that.$message.warning('客户属性不能为空！')
                }
                await that.$http.put(
                  '/wfpms-master-service/api/external/mtc_company/updatebyid',
                  that.form
                ).then(res => {
                  that.isSaveLoading = false;
                  if (res.data.success) {
                    if (that.drawer) {
                      that.drawer = false
                    }
                    that.$message.success(res.data.msg)
                    that.getListData()
                  } else {
                    that.isSaveLoading = false;
                    return that.$message.warning(res.data.msg)
                  }
                }).catch(error => { that.isSaveLoading = false })
              }
            })
            .catch(() => {
              this.isSaveLoading = false
            })
        } else {
          this.isSaveLoading = false
          return false
        }
      })
    },
    // 修改
    handleEdit(index, row) {
      // 去掉税号验证
      this.checkId = row.id
      this.isSaveLoading = false
      api.queryById(row.id).then(res => {
        const data = JSON.parse(JSON.stringify(res.data.data))
        this.form = {
          id: data.id,
          customerCode: data.customerCode,
          customerName: data.customerName,
          customerShortName: data.customerShortName,
          customerType: data.customerType + '',
          customerProperty: data.customerProperty,
          creditLimit: data.creditLimit,
          invoice: data.invoice,
          tin: data.tin,
          bank: data.bank,
          bankAccount: data.bankAccount,
          address: data.address,
          contact: data.contact,
          contactNumber: data.contactNumber,
    	  	email: data.email,
    	  	identityCard: data.identityCard,
    	  	remark: data.remark,
          contactAddress: data.contactAddress,
          telephoneNumber: data.telephoneNumber
        }
        this.checkedCus = data.customerProperty.split(',')
        this.arr = this.cusTypeList.filter(v => this.checkedCus.includes(v.dictLabel))
        if (this.arr.length == 0) {
          this.checkedCus.forEach(v => {
            this.cusTypeList.forEach(item => {
              if (v == item.dictLabel) {
                this.arr.push(item)
              }
            })
          })
        }
        console.log(this.checkedCus)
        console.log(this.arr)

        this.businessLicenseList = []
        this.authorizationList = []
        this.mattachmentInfoList = data.mattachmentInfoList ? data.mattachmentInfoList : []

        if (data.mattachmentInfoList && data.mattachmentInfoList.length > 0) {
          data.mattachmentInfoList.forEach(v => {
            if (v.fileType == '1') {
              this.businessLicenseList.push({ id: v.fileId, name: v.fileName, fileId: v.fileId, fileName: v.fileName })
            }
            if (v.fileType == '2') {
              this.authorizationList.push({ id: v.fileId, name: v.fileName, fileId: v.fileId, fileName: v.fileName })
            }
            if (v.fileType == '4') {
              this.drawerBillFile.push({ id: v.fileId, name: v.fileName, fileId: v.fileId, fileName: v.fileName })
            }
          })
        }
        console.log(this.businessLicenseList)

        this.drawer = true
        this.flag = false
      })
    },
    // 展示附件列表信息
    showRecieptList(index, row) {
      this.recieptDrawer = true;
      this.customerId = row.id;
      this.getRecieptListData();
    },
    // 删除确认
    async subDelete(id) {
      const data = {
        id: id
      }
      const res = await this.$http.delete(
        `/wfpms-master-service/api/external/mtc_company/deletebyid?id=${id}`
      )
      if (res.status == 200) {
        if (res.data.success) {
          this.$message.success(res.data.msg)
          this.startpage = 1
          this.getListData()
        } else {
          return this.$message.warning(res.data.msg)
        }
      } else {
        this.$message.error('删除失败！')
      }
    },

    add() {
      this.checkId = ''
      this.isSaveLoading = false
      // 增加税号验证
      this.basisRules.tin = [
        {
          pattern: /[^\u4E00-\u9FA5]/,
          message: '不能输入中文',
          trigger: 'blur'
        },
        {
          validator: this.checkTaxNum,
          trigger: 'blur'
        }
      ]
      this.flag = true
      this.drawer = true

      // this.queryparent()
      this.form = {
        customerCode: '',
        customerName: '',
        customerShortName: '',
        customerType: '1',
        customerProperty: '',
        creditLimit: '',
        invoice: '',
        tin: '',
        bank: '',
        bankAccount: '',
        address: '',
        contact: '',
        contactNumber: '',
    		email: '',
    		identityCard: '',
    		remark: '',
        telephoneNumber: '',
        contactAddress: ''
      },
      this.checkedCus = []
      this.businessLicenseList = []
      this.authorizationList = []
      this.mattachmentInfoList = []

      this.getDict()
    },
    // 每页显示的条数
    handleSizeChange(val) {
      this.pagesize = val
      this.getListData()
    },
    // 当前页
    handleCurrentChange(val) {
      this.startpage = val
      this.getListData()
    },
    // 文件上传
    handleBusinessLicense(params, type) {
      const file = params.file;
      const FormDatas = new FormData()
      FormDatas.append('fileArray', file)
      FormDatas.append('businessType', '04'); // 文件夹名称
      publicapi.getFileInfo(FormDatas).then(res => {
        this.$message.success('上传成功')
        const data = res.data.data
        data.forEach(v => {
          if (type == '1') {
            this.businessLicenseList.push(
              {
                id: data[0].fileId,
                name: data[0].fileName
              }
            )
          }
          if (type == '2') {
            this.authorizationList.push(
              {
                id: data[0].fileId,
                name: data[0].fileName
              }
            )
          }
          if (type == '4') {
            this.drawerBillFile.push(
              {
                id: data[0].fileId,
                name: data[0].fileName
              }
            )
          }
          console.log(this.mattachmentInfoList)
          this.mattachmentInfoList.push(
            {
              fileId: v.fileId,
              fileName: v.fileName,
              fileType: type
            }
          )
        })
      })
    },
    // 删除文件
    handleRemove(file, type) {
      console.log(file)
      this.mattachmentInfoList.forEach((v, index) => {
        if (v.fileType == type) {
          if (file.id == v.fileId) {
            this.mattachmentInfoList.splice(index, 1)
          }
        }
      })
      if (type == '1') {
        this.businessLicenseList.forEach((item, i) => {
          if (item.uid == file.uid) {
            this.businessLicenseList.splice(i, 1)
          }
        })
      }
      if (type == '2') {
        this.authorizationList.forEach((item, i) => {
          if (item.uid == file.uid) {
            this.authorizationList.splice(i, 1)
          }
        })
      }
    },
    // 删除客户信息
    handlerDelete(index, value) {
      this.$confirm('将删除本条客户信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.delete(`wfpms-master-service/api/external/mtc_company/deletebyid?id=${value.id}`).then(res => {
          this.getListData()
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 文件预览
    handlePreview(file) {
      console.log(file);
      this.fileInfo = file
      if (file.name.indexOf('jpg') != -1 || file.name.indexOf('png') != -1 || file.name.indexOf('jpeg') != -1) {
        axios({
          method: 'get',
          url: `${config.ConfigBaseURL}/wfpms-master-service/api/external/publics/file/down?id=${file.id}`,
          responseType: 'blob',
          params: {
            token: window.sessionStorage.getItem('token')
          }
        }).then(res => {
          const blob = new Blob([res.data], {
            type: 'application/png;charset=utf-8'
          });
          const url = window.URL.createObjectURL(blob);
          this.imgurl = url
          this.dialogVisible = true
        })
      } else {
        this.downLoadFile(file)
      }
    },
    // 文件下载
    downLoadFile(file) {
      axios({
        method: 'get',
        url: `${config.ConfigBaseURL}/wfpms-master-service/api/external/publics/file/down?id=${file.id}`,
        responseType: 'arraybuffer',
        params: {
          token: window.sessionStorage.getItem('token')
        }
      }).then(res => {
        console.log(res)
        const content = res.data
        const blob = new Blob([content]) // 构造一个blob对象来处理数据
        const link = document.createElement('a') // 创建a标签
        link.download = file.name // a标签添加属性
        link.style.display = 'none'
        link.href = URL.createObjectURL(blob, {
          type: `application/pdf`
        })
        document.body.appendChild(link)
        link.click() // 执行下载
        URL.revokeObjectURL(link.href) // 释放url
        document.body.removeChild(link) // 释放标签
      }).catch((error) => {

      })
    },
    /**
     * 修改文件
     */
    changeFile(fileList, val, item) {
      console.log(fileList)
      console.log(item)
      if (item == '1') {
        this.businessLicenseList = fileList
        if (this.businessLicenseList && this.businessLicenseList.length > 0) {
          this.businessLicenseList.forEach(v => {
            v.fileType = item
          })
        }
      }
      if (item == '2') {
        this.authorizationList = fileList
        if (this.authorizationList && this.authorizationList.length > 0) {
          this.authorizationList.forEach(v => {
            v.fileType = item
          })
        }
      }
      if (item == '4') {
        this.drawerBillFile = fileList
        if (this.drawerBillFile && this.drawerBillFile.length > 0) {
          this.drawerBillFile.forEach(v => {
            v.fileType = item
          })
        }
      }
    },
    // 打开信用额度窗口
    openCreaditLimit() {
      if (this.tableInfo == null) {
        return this.$message.warning('请选择一条数据')
      }
      this.formInline.creditLimit = ''
      this.creditDialog = true
      this.formInline.creditLimit = this.tableInfo.creditLimit
    },
    // 新增修改信用额度信息
    submitCreadit() {
      const params = {
        id: this.tableInfo.id,
        creditLimit: this.formInline.creditLimit
      }
      api.updateCreditLimit(params).then(res => {
        if (res.data.code != '0000') {
          return this.$message.error(res.data.msg)
        }
        this.creditDialog = false
        this.searchClick()
        this.$message.success('保存成功')
      })
    }
  }
}
</script>
<style>
   .el-message-box__message{
    word-wrap:break-word!important;
  }
</style>
<style lang="less" scoped>
@import "../../assets/searchfrom.less";
/deep/.el-tabs__nav-scroll {
  margin: 0 20px;
}

.kh_box /deep/.el-form-item__content {
  margin-left: 0 !important;
}

/deep/ .el-button--primary {
  background-color: #338ce8;
  border-color: #338ce8;
}

[v-cloak] {
  display: none;
}

.page {
  background: #ffffff;
  border-radius: 4px 4px 0 0;
  padding-right: 1rem;
}

.headerspan {
  background: #ffffff;
  border-bottom: 1px solid #e1e4eb;
  line-height: 40px;
  padding-left: 1rem;
}

.headerspan-item {
  line-height: 40px;
  padding-left: 1rem;
  font-size: 14px;
  color: #606266;
  letter-spacing: 0;
}

.box {
  background: #ffffff;
  border: 1px solid #e1e4eb;
  border-radius: 4px 4px 0 0;
  border-top: none;
}

.title {
  background: #f5f7fa;
  height: 40px;
  line-height: 40px;

  p {
    font-family: MicrosoftYaHei;
    font-size: 16px;
    color: #303133;
    letter-spacing: 0;
    line-height: 16px;
    padding-left: 14px;
    line-height: 40px;
  }
}

/deep/ .el-drawer__header {
  margin-bottom: 0;
  padding: 16px;
  border-bottom: 1px solid gainsboro;
}

/deep/ .demo-drawer__footer {
  text-align: right;
  padding-right: 1rem;
  border-top: 1px solid #c8cfde;
  background-color: #f5f7fa;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  line-height: 50px;
  z-index: 20;
}

/deep/ .el-table .cell {
  white-space: nowrap;
}

/deep/ .el-form-item--mini .el-form-item__label {
  line-height: 0;
}

/deep/ .el-pagination {
  text-align: right;
  padding: 10px 5px;
}

/deep/ .el-table th > .cell {
  font-family: PingFangSC-Semibold;
  font-size: 14px;
  color: #606266;
}

/deep/ .el-table .el-button:focus,
.el-table .el-button:hover {
  background-color: #fff;
  border: 1px solid #e1e4eb;
}

/deep/ .el-table .el-button--mini {
  color: #1684f6;
  border-color: transparent;
  background: transparent;
}

/deep/ .el-table th {
  border-left: 1px solid #ebeef5;
}

/deep/ .el-table th:nth-child(1) {
  border-left: none;
}

/deep/ .el-table--striped .el-table__body tr.el-table__row--striped td {
  background: #f5f7fa;
}

/deep/.el-pagination.is-background .btn-next,
/deep/ .el-pagination.is-background .btn-prev,
/deep/ .el-pagination.is-background .el-pager li {
  background: #ffffff;
  border: 1px solid #e1e4eb;
  border-radius: 3px;
  border-radius: 3px;
}

/deep/ .el-button + .el-button {
  margin-left: 3px;
}

/deep/ .el-drawer__open .el-drawer.rtl {
  background: #f5f7fa;
}

.btn /deep/ .el-button--mini,
.el-button--mini.is-round {
  padding: 7px 6px;
}

.selectBox {
  justify-content: space-between;
  display: flex;
  flex-direction: row-reverse;
  background: #ffffff;
  border: 1px solid #e1e4eb;
  border-bottom: 0;
  border-left: none;
  height: 50px;
  position: relative;
  display: flex;
  align-items: center;
  padding-left: 16px;
  padding-right: 24px;
}

.kehuguanxi /deep/ .el-drawer__open .el-drawer.rtl {
  width: 30% !important;
}

/deep/ .el-drawer__header {
  padding: 8px 20px 8px;
}

/deep/ .el-drawer__body {
  overflow-y: auto;
  margin-bottom: 50px;
}

// .leftbox /deep/ .el-input {
// 	width: 60% !important;
// }
.formt-itm {
  border-bottom: 1px solid gainsboro;
  margin-bottom: 4px;
  padding-left: 1rem;
  padding-right: 1rem;
  display: flex;
  justify-content: space-between;
  letter-spacing: 0;
  font-family: MicrosoftYaHei;
  font-size: 14px;
  color: #303133;
  line-height: 40px;

  i {
    color: #909399;
  }
}
.inpitclass {
    .el-input {
        width: 96% !important;
    }
    .el-textarea{
        width: 96% !important;
    }
}

/deep/ .el-form-item {
    margin-bottom: 18px;
}

</style>
<style>
  .el-message-box__message{
    word-wrap:break-word!important;
    max-height: 100px;
    overflow: auto;
  }
</style>